// 脱敏手机号
export function maskedPhone(phone: string): string {
  return phone.replace(/^(\d{3})\d{4}(\d+)/, '$1****$2')
}

export function maskedEmail(email: string): string {
  const split_index = email.indexOf('@') // 获取 @ 符号的位置索引
  const username = email.slice(0, split_index) // 获取用户名部分
  const domain = email.slice(split_index) // 获取域名部分
  const masked_username = `${username.slice(0, 3)}****${username.slice(-2)}` // 对用户名部分进行脱敏处理
  const masked_email = `${masked_username}${domain}`
  return masked_email
}

export function maskData(isPhone: boolean, dataStr: string): string {
  if (isPhone) {
    return maskedPhone(dataStr)
  } else {
    return maskedEmail(dataStr)
  }
}
